<template>
	<view style="margin-top: 5rpx;">
		<scroll-view :scroll-top="scrollTop" :scroll-y="isSlide" class="scroll-Y" @scrolltoupper="upper" @scrolltolower="lower"  style="height: 92vh;width: 750rpx;background: #FFFFFF;z-index: 12121;" :lower-threshold="lower_threshold"  :refresher-triggered="triggered" @refresherrefresh="onRefresh" :refresher-threshold="100" @refresherpulling="pulling" refresher-background="#FFFFFF">
			<view v-if="fatherData.length != 0">
				<view v-for="(itme,index) in fatherData" :key="index" style="padding: 40rpx;" @tap="goshanchu(itme)">
					<view style="display: flex;align-items: center;" >
						<view>
							<image :src="itme.avatar" style="width: 80rpx;height: 80rpx;border-radius: 50%;" ></image>
						</view>
						<view style="margin-left: 20rpx;display: flex;justify-content: space-between;align-items: center;width: 550rpx;">
							<view>
								<view style="font-size: 28rpx;font-weight: bold;">{{itme.nick_name}}</view>
								<view style="font-size: 24rpx;color: #E4E4E4;">{{itme.time}}</view>
							</view>
							<view style="display: flex;align-items: center;">
								<view>
									<image :src="dianzan" style="width: 50rpx;height: 50rpx;"></image>
								</view>
								<view style="font-size: 26rpx;" v-if="num_shu == 0">{{itme.like_count}}</view>
							</view>
						</view>
					</view>
					<view style="margin-top: 10rpx;font-size: 28rpx;" v-if="num_shu == 0">{{itme.content}}</view>
					<view style="height: 2rpx;width: 670rpx;background-color: #F5F5F5;margin: 15rpx 0 0 0;"></view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		
		props: {
			num_shu: Number,
			id: Number,
			isSlide: Boolean,
			downHeight: Number
		},
		
		data() {
			return {
				triggered: false,
				isshow: false,
				dianzan: "http://img.curiousmore.com/46955563369",
				user_id: "",
				isshow_fabu: false,
				fatherData: []
			}
		},
		
		methods: {
			details() {
				let me = this
				uni.request({
					url: "https://curiousmore.com/qmore/message/noteUser/queryListPage",
					data: {
						status: 1,
						pageSize: 1,
						currentPage: 1,
						is_teach_paypal: true,
						id: me.id
					},
					success: (res) => {
						me.fatherData = []
						if(res.data.code == 0){
							me.carryData = res.data.data[0]
							if(me.num_shu == 0){
								me.fatherData = me.carryData.map.noteCommentEntities
							}else {
								me.fatherData = me.carryData.map.likeinfo
							}
							if(me.num_shu == 0 && me.fatherData.length != 0){
								this.fatherData.forEach((itme) => {
									itme.time =	me.day_fun(itme.create_time)
									itme.avatar = itme.map.userinfo.avatar
									itme.nick_name = itme.map.userinfo.nick_name
								})
							}
							
							if(me.num_shu == 1 && me.fatherData.length != 0 ){
								me.fatherData.forEach((itme) => {
									if(itme.hasOwnProperty("local_time")){
										itme.shijian = itme.local_time
									}else {
										itme.shijian = itme.create_time
									}
									if(!itme.hasOwnProperty("avatar")){
										itme.avatar = "http://img.curiousmore.com/2DE-B2A7648763A5/Documents/com_tencent_imsdk_data/image/huihe_453146001"
									}
									itme.time = me.day_fun_(itme.shijian)
								})
							}
						}
						me.$emit("zizujian",me.fatherData.length)
					}
				})
			},
			
			goshanchu(itme) {
				if(this.num_shu == 0 && itme.user_id == this.user_id ){
					this.shanchu(itme)
				}
			},
			 
		    shanchu(itme) {
				let me = this
				uni.showModal({
				    content: '是否删除动态',
					cancelColor: "#FF7300",
				    success: function (res) {
				        if (res.confirm) {
				            me.zizujian(itme.id)
				        } else if (res.cancel) {
				           
				        }
				    }
				});
			},
			
			zizujian(index){
				let me = this
				uni.request({
					url: "https://curiousmore.com/qmore/message/noteComment/delete",
					data: {
						id: index
					},
					method: "get",
					success: (res) => {
						if(res.data.code == 0){
							uni.showToast({
								title: "删除成功"
							})
							me.details()
						}
						
					},
					fail: (err) => {
						console.log(err)
					}
				})
			},
			
			day_fun(day_time){
				let dangqian = new Date().getTime()
				let day_time_ = day_time.replace(/-/g, '/')
				let day = new Date(day_time_).getTime()
				let chazhi = dangqian - day
				let fanhui = ""
				if(chazhi > 30*24*60*60*1000){
					fanhui = "一个月前"
				}else if(chazhi > 7*24*60*60*1000){
					fanhui = "一周前"
				}else if(chazhi > 24*60*60*1000 && 7*24*60*60*1000 > chazhi){
					let tian = (chazhi / (24*60*60*1000)).toFixed(0)
					fanhui = tian + "天前"
				}else if(chazhi < 24*60*60*1000 && chazhi > 60*60*1000){
					let shi = (chazhi / (60*60*1000)).toFixed(0)
					fanhui = shi + "小时前"
				}else if(chazhi < 60*60*1000 ){
					let fen = (chazhi / (60*1000)).toFixed(0)
					if(fen == 0){
						fanhui = "1分钟前"
					}else{
						fanhui = fen + "分钟前"
					}
				}
				return fanhui
			},
			
			day_fun_(day_time){
				let dangqian = new Date().getTime()
				let chazhi = dangqian - day_time
				let fanhui = ""
				if(chazhi > 30*24*60*60*1000){
					fanhui = "一个月前"
				}else if(chazhi > 7*24*60*60*1000){
					fanhui = "一周前"
				}else if(chazhi > 24*60*60*1000 && 7*24*60*60*1000 > chazhi){
					let tian = (chazhi / (24*60*60*1000)).toFixed(0)
					fanhui = tian + "天前"
				}else if(chazhi < 24*60*60*1000 && chazhi > 60*60*1000){
					let shi = (chazhi / (60*60*1000)).toFixed(0)
					fanhui = shi + "小时前"
				}else if(chazhi < 60*60*1000 ){
					let fen = (chazhi / (60*1000)).toFixed(0)
					if(fen == 0){
						fanhui = "1分钟前"
					}else{
						fanhui = fen + "分钟前"
					}
				}
				return fanhui
			},
			
			onRefresh() {
				this.triggered = true
				setTimeout(() => {
					this.triggered = false
				},1000)
				this.$emit("onRefresh",false)
			}
		},
		onLoad() {
			try{
				this.user_id = uni.getStorageSync('userif_list').user_id
			}catch(e){}
			this.details()
		}
	}
</script>

<style scoped>
	.clc {
		background-color: transparent;
	}
</style>
